package com.wm.wmcrm.sys.controller;

import com.wm.wmcrm.common.annotation.SystemLog;
import com.wm.wmcrm.common.result.IgnoredResultWrapper;
import com.wm.wmcrm.common.result.ResultWrapper;
import com.wm.wmcrm.common.util.PageUtils;
import com.wm.wmcrm.sys.entity.SysRole;
import com.wm.wmcrm.sys.entity.SysUser;
import com.wm.wmcrm.sys.model.SysUserQueryDTO;
import com.wm.wmcrm.sys.service.ISysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 系统用户 前端控制器
 * </p>
 *
 * @author wm
 * @since 2023-02-11
 */
@Api(tags = "系统用户",value = "SysUser")
@RestController
@RequestMapping("/sys/sysUser")
public class SysUserController {
    @Resource
    private ISysUserService sysUserService;

    //查询用户列表
    @ApiOperation(value = "查询系统用户1",notes="查询用户1")
    @GetMapping("/queryList")
    public PageUtils queryList(SysUserQueryDTO userQueryDTO){
        return sysUserService.queryPage(userQueryDTO);
    }

//    @ApiOperation(value = "检查用户名称是否已存在",notes="用户名称")
//    @GetMapping("/checkUsernameExist")
//    public boolean checkUsernameExist(String username){
//        return sysUserService.checkUsernameExist(username);
//    }

    @SystemLog("更新用户")
    @ApiOperation(value = "更新用户",notes = "用户")
    @PostMapping("/updateOne")
    public boolean updateOne(@RequestBody SysUser sysUser ){
        return sysUserService.updateOne(sysUser);
    }


    @SystemLog("批量删除用户")
    @ApiOperation(value = "批量删除用户",notes = "删除用户")
    @PostMapping("/deleteList")
    public int deleteList(@RequestBody List<String> userIdList){
        return sysUserService.deleteBatch(userIdList);
    }

    @ApiOperation(value = "检查字段值是否存在",notes="字段值")
    @GetMapping("/checkExist")
    public boolean checkExist(String key,String value){
        return sysUserService.checkExist(key,value);
    }
    @SystemLog("添加用户")
    @ApiOperation(value = "添加用户",notes="用户")
    @PostMapping("/save")
    public boolean save(@RequestBody SysUser sysUser){
        return sysUserService.saveUser(sysUser);
    }

    @SystemLog("删除用户")
    @ApiOperation(value = "删除用户",notes = "用户")
    @GetMapping("/deleteOne")
    public boolean deleteOne(String userId){
        return sysUserService.deleteOne(userId);
    }
    @SystemLog("修改用户状态")
    @ApiOperation(value = "修改用户状态",notes = "用户状态")
    @GetMapping("/updateStatus")
    public boolean updateStatus(int userId,int status){
        return sysUserService.updateStatusById(userId,status);
    }
    @ApiOperation(value = "查询系统用户",notes="查询用户")
    @GetMapping("/list")
    public List<SysUser> list(){
        return sysUserService.list();
    }

    //@IgnoredResultWrapper忽视wrapper结果信息
    @IgnoredResultWrapper
    @ApiOperation(value = "查询系统用户1",notes="查询用户1")
    @GetMapping("/list1")
    public List<SysUser> list1(){
        return sysUserService.list();
    }


    //自定义ResulWrapper结果
    @ApiOperation(value = "查询系统用户2",notes="查询用户2")
    @GetMapping("/list2")
    public ResultWrapper list2(){
        ResultWrapper wrapper = new ResultWrapper();
        wrapper.setCode("200");
        wrapper.setData(sysUserService.list());
        wrapper.setMessage("自定义ResulWrapper结果");
        return wrapper;
    }

}
